﻿using System;
using System.Security;
using System.Collections.Generic;
using Mono.Xml;
using UnityEngine;
namespace GX
{
    public class UIConfig
    {
        static readonly Dictionary<string, UICO> Map = new Dictionary<string, UICO>();
        static readonly Dictionary<int, UICO> MapByHashCode = new Dictionary<int, UICO>();
        static public UICO Get(string name)
        {
            UICO info;
            Map.TryGetValue(name, out info);
            return info;
        }
        static public UICO Get(int hashCode)
        {
            UICO info;
            MapByHashCode.TryGetValue(hashCode, out info);
            return info;
        }
        public static void Parse()
        {
            var ta = Resources.Load("UIManifest") as TextAsset;
            SecurityParser SP = new SecurityParser();
            SP.LoadXml(ta.text);
            SecurityElement doc = SP.ToXml();
            foreach (var node in doc.Children)
            {
                var co = new UICO();
                co.Parse(node as SecurityElement);
                Map[co.name] = co;
                MapByHashCode[co.hashCode] = co;
            }
        }
    }
}